import request from "@/utils/request";

const baseURL = "/train/order";

/**
 * @param data 订单信息
 * @returns 订单id
 */
export const createOrder = (data: CreateOrderReq) =>
  request<Res<string>>({
    url: `${baseURL}/create`,
    method: "post",
    data,
  });

/**
 * @param orderId 订单id
 * @returns 订单基础信息
 */
export const getOrderById = (orderId: string) =>
  request<Res<OrderInfoResp>>({
    url: `${baseURL}/get-by-id`,
    method: "get",
    params: { id: orderId },
  });

/**
 * @param orderNo 订单号
 * @returns 订单基础信息
 */
export const getOrderByOrderNo = (orderNo: string) =>
  request<Res<OrderInfoResp>>({
    url: `${baseURL}/get-by-order-no`,
    method: "get",
    params: { orderNo },
  });

/**
 * 取消订单
 * @param orderId 订单id
 * @returns 订单基础信息
 */
export const cancelOrder = (orderId: string) =>
  request<Res<boolean>>({
    url: `${baseURL}/cancel`,
    method: "post",
    data: { id: orderId },
  });

/**
 * @param orderId 订单id
 * @returns 微信支付参数
 */
export const getBrandWCPayRequest = (orderId: string) =>
  request<Res<BrandWCPayRequest>>({
    url: `${baseURL}/get-brand-wc-pay-request`,
    method: "post",
    data: { id: orderId },
  });

/**
 * 获取我的订单列表
 * @returns 订单列表
 */
export const listMemberOrder = () =>
  request<Res<OrderListResp[]>>({
    url: `${baseURL}/list-member-order`,
    method: "get",
  });
